using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;

public partial class Admin_KhachHangUpdate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!IsPostBack)
        {
            LoadData();
        }
       
    }

    private void LoadData()
    {
        try
        {
            int iD = int.Parse(Request.QueryString["iD"].ToString());
            txt_makh.Text = iD.ToString();
            tbKhachHang khachhang = tbKhachHangBUS.GetByID(iD);
            txt_hoten.Text=khachhang .HoTen ;
            ddl_gioitinh.SelectedValue = khachhang.GioiTinh;
            txt_ngaysinh.Text = khachhang.NgaySinh.ToString("dd/MM/yyyy");
            txt_email.Text=khachhang .Email ;
            txt_taikhoan.Text = khachhang.TaiKhoan;
            txt_matkhau.Text=khachhang .MatKhau ;
            txt_diachi.Text = khachhang.DiaChi;
            txt_dienthoai.Text = khachhang.DienThoai;
            txt_sotknh.Text = khachhang.SoTKNH;
        }
        catch
        {
            Response.Redirect("~/Admin/KhachHangDanhSach.aspx");
        }
    }

    protected void btn_sua_Click(object sender, EventArgs e)
    {
        try
        {
            int iD = int.Parse(Request.QueryString["iD"]);
            tbKhachHang khachhang = tbKhachHangBUS.GetByID(iD);
            khachhang.HoTen = txt_hoten.Text;
            khachhang.GioiTinh = ddl_gioitinh.SelectedValue;
            khachhang.NgaySinh =DateTime .Parse ( txt_ngaysinh.Text);
            khachhang.Email = txt_email.Text;
            khachhang.TaiKhoan = txt_taikhoan.Text;    
            khachhang.MatKhau = txt_matkhau.Text;
            khachhang.DiaChi =txt_diachi.Text;
            khachhang.DienThoai = txt_dienthoai.Text;
            khachhang.SoTKNH = txt_sotknh.Text;
            tbKhachHangBUS.Update(khachhang);
        }
        catch
        {

        }
        Response.Redirect("~/Admin/KhachHangDanhSach.aspx");
        Response.Redirect(Request.RawUrl);
    }

}

